﻿using NavigationShowcase.ViewModels;
using WinRTFramework.Common;
using WinRTFramework.Interfaces.Navigation.Page;

// The Item Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234232

namespace NavigationShowcase
{
    /// <summary>
    /// A page that displays details for a single item within a group while allowing gestures to
    /// flip through other items belonging to the same group.
    /// </summary>
    public sealed partial class ItemDetailPage : LayoutAwarePage, ICareAboutReady
    {
        public ItemDetailPage()
        {
            this.InitializeComponent();
        }

        #region ICareAboutReady
        public void OnReady()
        {
            //This avoids the problem in the FlipView implementation which causes the CollectionView's CurrentItem to be reset as soon as the CollectionView is applied to the FlipView's ItemsSource
            var vm = ((ItemDetailPageViewModel_Showcase) DataContext);
            var temp = vm.ItemsView.CurrentItem;
            flipView.ItemsSource = vm.ItemsView;
            vm.ItemsView.MoveCurrentTo(temp);
        }
        #endregion
    }
}
